<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="Nginx, 鸟鸟">
    <meta name="description" content="大家好，我是鸟鸟，今年20岁，喜欢打篮球，搭建的这个博客是用来记录平时的一些学习笔记和心得">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>Nginx | 鸟鸟</title>
    <link rel="icon" type="image/png" href="/yueyueniao-gif/favicon.png">

    <link rel="stylesheet" type="text/css" href="/yueyueniao-gif/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/yueyueniao-gif/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/yueyueniao-gif/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/yueyueniao-gif/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/yueyueniao-gif/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/yueyueniao-gif/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/yueyueniao-gif/css/my.css">

    <script src="/yueyueniao-gif/libs/jquery/jquery.min.js"></script>

<meta name="generator" content="Hexo 5.0.2"><link rel="alternate" href="/yueyueniao-gif/atom.xml" title="鸟鸟" type="application/atom+xml">
<link rel="stylesheet" href="/yueyueniao-gif/css/prism-tomorrow.css" type="text/css"></head>


<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/yueyueniao-gif/" class="waves-effect waves-light">
                    
                    <img src="/yueyueniao-gif/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">鸟鸟</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/yueyueniao-gif/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/yueyueniao-gif/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/yueyueniao-gif/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/yueyueniao-gif/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/yueyueniao-gif/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/yueyueniao-gif/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言板</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/yueyueniao-gif/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友情链接</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/yueyueniao-gif/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">鸟鸟</div>
        <div class="logo-desc">
            
            大家好，我是鸟鸟，今年20岁，喜欢打篮球，搭建的这个博客是用来记录平时的一些学习笔记和心得
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/yueyueniao-gif/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/yueyueniao-gif/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/yueyueniao-gif/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/yueyueniao-gif/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/yueyueniao-gif/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/yueyueniao-gif/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/yueyueniao-gif/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友情链接
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/blinkfox/hexo-theme-matery" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/blinkfox/hexo-theme-matery" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('/yueyueniao-gif/medias/featureimages/18.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">Nginx</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/yueyueniao-gif/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        margin: 35px 0 15px 0;
        padding-left: 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        height: calc(100vh - 250px);
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    .toc-fixed .toc-link::before{
        position: fixed!important;/*当toc的位置改为fixed时，.toc-link::before也要改为fixed*/
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #toc-content .is-active-link::before {
        background-color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/yueyueniao-gif/tags/Nginx/">
                                <span class="chip bg-color">Nginx</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/yueyueniao-gif/categories/Nginx/" class="post-category">
                                Nginx
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2020-08-20
                </div>
                

                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    1.7k
                </div>
                

                

                
            </div>
        </div>
        <hr class="clearfix">
        <div class="card-content article-card-content">
            <div id="articleContent">
                <h3 id="Nginx简介"><a href="#Nginx简介" class="headerlink" title="Nginx简介"></a>Nginx简介</h3><p>Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件（IMAP/POP3）代理服务器，在BSD-like 协议下发行。其特点是占有内存少，并发能力强，事实上nginx的并发能力在同类型的网页服务器中表现较好，中国大陆使用nginx网站用户有：百度、京东、新浪、网易、腾讯、淘宝等。</p>
<h6 id="nginx最高并发支持50000个"><a href="#nginx最高并发支持50000个" class="headerlink" title="nginx最高并发支持50000个"></a>nginx最高并发支持50000个</h6><h4 id="正向代理和反向代理"><a href="#正向代理和反向代理" class="headerlink" title="正向代理和反向代理"></a>正向代理和反向代理</h4><h6 id="正向代理"><a href="#正向代理" class="headerlink" title="正向代理"></a>正向代理</h6><p>在客户端（浏览器）配置代理服务器，通过代理服务器进行互联网访问</p>
<p><img src="https://s3.jpg.cm/2020/08/21/ukebt.png"></p>
<h6 id="反向代理"><a href="#反向代理" class="headerlink" title="反向代理"></a>反向代理</h6><p>反向代理，其实客户端对代理是无感知的，因为哭护短不需要做任何配置就可以访问，我们只需要将请求发送到反向代理服务器，由反向代理服务器去选择目标服务器获取数据后，在返回给客户端，吃屎反向代理服务器和目标服务器对外就是一个服务器，暴露的是代理服务器地址，隐藏了真是服务器IP地址</p>
<p><img src="https://s3.jpg.cm/2020/08/21/ukl4R.jpg"></p>
<h4 id="负载均衡"><a href="#负载均衡" class="headerlink" title="负载均衡"></a>负载均衡</h4><p>我们增加了服务器的数量，然后将请求分发到各个服务器上，将原先的请求集中到单个服务器上的情况改为将请求分发到多个服务器上，将负载分发到不同的服务器，也就是我们所说的负载均衡</p>
<p><img src="https://s3.jpg.cm/2020/08/21/ukU7X.png"></p>
<h4 id="动静分离"><a href="#动静分离" class="headerlink" title="动静分离"></a>动静分离</h4><p>为了加快网站的解析速度，可以把动态页面和静态页面由不同的服务器来解析，加快解析速度。降低原来单个服务器的压力</p>
<p><img src="https://s3.jpg.cm/2020/08/21/ukHP6.png"></p>
<h3 id="Nginx的安装"><a href="#Nginx的安装" class="headerlink" title="Nginx的安装"></a>Nginx的安装</h3><h5 id="安装Nginx"><a href="#安装Nginx" class="headerlink" title="安装Nginx"></a>安装Nginx</h5><pre class=" language-yml"><code class="language-yml">version: '3.1'
services:
  nginx:
    restart: always
    image: daocloud.io/library/nginx:latest
    container_name: nginx
    ports:
      - 80:80
    volumes:
      - /opt/docker_nginx/conf.d/:/etc/nginx/conf.d</code></pre>
<h5 id="Nginx配置文件"><a href="#Nginx配置文件" class="headerlink" title="Nginx配置文件"></a>Nginx配置文件</h5><p>首先进入nginx容器内部，然后进入容器内部的 /etc/nginx/</p>
<p>然后直接cat nginx.conf，就可以看到以下文件内容了</p>
<pre class=" language-json"><code class="language-json">worker_processes  <span class="token number">1</span><span class="token punctuation">;</span>

error_log  /var/log/nginx/error.log warn<span class="token punctuation">;</span>
pid        /var/run/nginx.pid<span class="token punctuation">;</span>

#以上统称为全局快
#worker_processes它的数值越大，Nginx的并发能力越强
#error_log代表Nginx的错误日志存放位置
#pid代表Nginx的运行表示（不用关心）

events &amp;#<span class="token number">123</span><span class="token punctuation">;</span>
    worker_connections  <span class="token number">1024</span><span class="token punctuation">;</span>
&amp;#<span class="token number">125</span><span class="token punctuation">;</span>
#event块
#worker_connections它的数值越大，Nginx并发能力越强

http &amp;#<span class="token number">123</span><span class="token punctuation">;</span>
    include       /etc/nginx/mime.types<span class="token punctuation">;</span>
    default_type  application/octet-stream<span class="token punctuation">;</span>
    include /etc/nginx/conf.d/*.conf<span class="token punctuation">;</span>
&amp;#<span class="token number">125</span><span class="token punctuation">;</span>
#http块
#include代表引入一个外部的文件        -----> /mine.types中存放着大量的媒体类型
#include /etc/nginx/conf.d/*.conf<span class="token punctuation">;</span> ------>引入了conf.d目录下的以.conf为结尾的配置文件</code></pre>
<p>其中http块中的 #include /etc/nginx/conf.d/*.conf 引入的文件如下：</p>
<pre class=" language-json"><code class="language-json">server &amp;#<span class="token number">123</span><span class="token punctuation">;</span>
    listen       <span class="token number">80</span><span class="token punctuation">;</span>
    listen  <span class="token punctuation">[</span><span class="token operator">:</span><span class="token operator">:</span><span class="token punctuation">]</span><span class="token operator">:</span><span class="token number">80</span><span class="token punctuation">;</span>
    server_name  localhost<span class="token punctuation">;</span>

    location / &amp;#<span class="token number">123</span><span class="token punctuation">;</span>
        root   /usr/share/nginx/html<span class="token punctuation">;</span>
        index  index.html index.htm<span class="token punctuation">;</span>
    &amp;#<span class="token number">125</span><span class="token punctuation">;</span>
    #location
    #root：将接收到的请求根据/usr/share/nginx/html去查找静态资源
    #index<span class="token operator">:</span> 默认去上述路径中找到index.html或者index.htm文件
&amp;#<span class="token number">125</span><span class="token punctuation">;</span>
#server块
# listen： 代表Nginx监听端口
#localhost：代表Nginx接收请求的ip</code></pre>
<h3 id="Nginx的使用"><a href="#Nginx的使用" class="headerlink" title="Nginx的使用"></a>Nginx的使用</h3><h5 id="基于Nginx实现反向代理"><a href="#基于Nginx实现反向代理" class="headerlink" title="基于Nginx实现反向代理"></a>基于Nginx实现反向代理</h5><pre><code>准备一个目标服务器
启动一个tomcat服务器
编写nginx配置文件，通过nginx访问tomcat服务器</code></pre>
<pre class=" language-json"><code class="language-json">server&amp;#<span class="token number">123</span><span class="token punctuation">;</span>
  listen <span class="token number">80</span><span class="token punctuation">;</span>
  server_name localhost<span class="token punctuation">;</span>
    #基于反向代理访问到tomcat服务器
  location / &amp;#<span class="token number">123</span><span class="token punctuation">;</span>
    proxy_pass http<span class="token operator">:</span>//<span class="token number">39.102</span>.<span class="token number">66.143</span><span class="token operator">:</span><span class="token number">8081</span>/<span class="token punctuation">;</span>
  &amp;#<span class="token number">125</span><span class="token punctuation">;</span>
&amp;#<span class="token number">125</span><span class="token punctuation">;</span></code></pre>
<h6 id="关于nginx的location路径映射"><a href="#关于nginx的location路径映射" class="headerlink" title="关于nginx的location路径映射"></a>关于nginx的location路径映射</h6><p>优先级关系：</p>
<p>(location=) &gt; (location /xxx) &gt; (location ^<del>) &gt; (location ~,</del>*) &gt; (location /起始路径) &gt; (location /)</p>
<pre class=" language-json"><code class="language-json">#<span class="token number">1</span>. = 匹配
location = / &amp;#<span class="token number">123</span><span class="token punctuation">;</span>
   #精准匹配，主机名后面不能带任何的字符串
&amp;#<span class="token number">125</span><span class="token punctuation">;</span></code></pre>
<pre class=" language-json"><code class="language-json">#<span class="token number">2</span>. 通用匹配
location /xxx &amp;#<span class="token number">123</span><span class="token punctuation">;</span>
   #匹配所有以/xxx开头的路径
&amp;#<span class="token number">125</span><span class="token punctuation">;</span></code></pre>
<pre class=" language-json"><code class="language-json">#<span class="token number">3</span>. 正则匹配
location ~ /xxx &amp;#<span class="token number">123</span><span class="token punctuation">;</span>
   #匹配所有以/xxx开头的路径
&amp;#<span class="token number">125</span><span class="token punctuation">;</span></code></pre>
<pre class=" language-json"><code class="language-json">#<span class="token number">4</span>. 匹配开头路径
location ^~ /images/ &amp;#<span class="token number">123</span><span class="token punctuation">;</span>
   #匹配所有以/images开头的路径
&amp;#<span class="token number">125</span><span class="token punctuation">;</span></code></pre>
<pre class=" language-json"><code class="language-json">#<span class="token number">5</span>. 匹配结尾路径
location ~* \.(gif|jpg|png<span class="token punctuation">)</span>$ &amp;#<span class="token number">123</span><span class="token punctuation">;</span>
   #匹配以gif或者jpg或者png为结尾的路径
&amp;#<span class="token number">125</span><span class="token punctuation">;</span></code></pre>
<h5 id="负载均衡-1"><a href="#负载均衡-1" class="headerlink" title="负载均衡"></a>负载均衡</h5><pre><code>Nginx为我们默认提供了三种负载均衡的策略：
  1.轮询：
     将客户端发起的请求，平均分配给每一台服务器
  2.权重：
     会将客户端的请求，根据的权重值不同，分配不同的数量
  3.ip_hash：
     基于发起请求的客户端地址不同，他始终会将请求发送到指定的服务器上,这种方式可以解决session相关的问题</code></pre>
<h6 id="轮询"><a href="#轮询" class="headerlink" title="轮询"></a>轮询</h6><p>想实现Nginx的轮询负载均衡机制，只需要在配置文件中添加一下内容</p>
<pre class=" language-json"><code class="language-json">upstream 自己起的名字&amp;#<span class="token number">123</span><span class="token punctuation">;</span>
    server <span class="token number">39.102</span>.<span class="token number">66.143</span><span class="token operator">:</span><span class="token number">8081</span><span class="token punctuation">;</span>
    server <span class="token number">39.102</span>.<span class="token number">66.143</span><span class="token operator">:</span><span class="token number">8080</span><span class="token punctuation">;</span>
    server ip<span class="token operator">:</span>port<span class="token punctuation">;</span>
    ...
&amp;#<span class="token number">125</span><span class="token punctuation">;</span>
server &amp;#<span class="token number">123</span><span class="token punctuation">;</span>
    listen       <span class="token number">80</span><span class="token punctuation">;</span>
    server_name  localhost<span class="token punctuation">;</span>

    location / &amp;#<span class="token number">123</span><span class="token punctuation">;</span>
       proxy_pass http<span class="token operator">:</span>//自己起的名字/<span class="token punctuation">;</span>
    &amp;#<span class="token number">125</span><span class="token punctuation">;</span>
&amp;#<span class="token number">125</span><span class="token punctuation">;</span></code></pre>
<h6 id="权重"><a href="#权重" class="headerlink" title="权重"></a>权重</h6><p>想实现Nginx的权重负载均衡机制，只需要在轮询中增加weight权重比例</p>
<pre class=" language-json"><code class="language-json">upstream 自己起的名字&amp;#<span class="token number">123</span><span class="token punctuation">;</span>
    server <span class="token number">39.102</span>.<span class="token number">66.143</span><span class="token operator">:</span><span class="token number">8081</span><span class="token punctuation">;</span>
    server <span class="token number">39.102</span>.<span class="token number">66.143</span><span class="token operator">:</span><span class="token number">8080</span><span class="token punctuation">;</span>
    server ip<span class="token operator">:</span>port weight=权重比例<span class="token punctuation">;</span>
    server ip<span class="token operator">:</span>port weight=权重比例<span class="token punctuation">;</span>
    ...
&amp;#<span class="token number">125</span><span class="token punctuation">;</span>
server &amp;#<span class="token number">123</span><span class="token punctuation">;</span>
    listen       <span class="token number">80</span><span class="token punctuation">;</span>
    server_name  localhost<span class="token punctuation">;</span>

    location / &amp;#<span class="token number">123</span><span class="token punctuation">;</span>
       proxy_pass http<span class="token operator">:</span>//自己起的名字/<span class="token punctuation">;</span>
    &amp;#<span class="token number">125</span><span class="token punctuation">;</span>
&amp;#<span class="token number">125</span><span class="token punctuation">;</span></code></pre>
<h6 id="ip-hash"><a href="#ip-hash" class="headerlink" title="ip_hash"></a>ip_hash</h6><p>只需要加一个ip_hash</p>
<pre><code>upstream 自己起的名字&amp;#123;
    ip_hsah;
    server 39.102.66.143:8081;
    server 39.102.66.143:8080;
    server ip:port;
    ...
&amp;#125;
server &amp;#123;
    listen       80;
    server_name  localhost;

    location / &amp;#123;
       proxy_pass http://自己起的名字/;
    &amp;#125;
&amp;#125;</code></pre>
<h5 id="动静分离-1"><a href="#动静分离-1" class="headerlink" title="动静分离"></a>动静分离</h5><pre><code>Nginx的并发能力公式
   worker_processes*worker_connections/4|2=Nginx最终的并发能力
   动态资源需要/4，静态资源需要/2
Nginx通过动静分离，来提升Nginx的并发能力，更快的给用户响应</code></pre>
<h6 id="动态资源代理"><a href="#动态资源代理" class="headerlink" title="动态资源代理"></a>动态资源代理</h6><pre class=" language-json"><code class="language-json">#配置如下
location / &amp;#<span class="token number">123</span><span class="token punctuation">;</span>
    proxy_pass 路径；
&amp;#<span class="token number">125</span><span class="token punctuation">;</span></code></pre>
<h6 id="静态资源路径"><a href="#静态资源路径" class="headerlink" title="静态资源路径"></a>静态资源路径</h6><pre class=" language-json"><code class="language-json">#配置如下
location / &amp;#<span class="token number">123</span><span class="token punctuation">;</span>
    root 静态资源路径<span class="token punctuation">;</span>
    index 默认访问路径下的什么资源<span class="token punctuation">;</span>
    autoindex on；  #代表展示静态资源下的全部内容，以列表形式展开
&amp;#<span class="token number">125</span><span class="token punctuation">;</span>


#先修改docker，添加一个数据卷，映射到Nginx服务器的一个目录
version<span class="token operator">:</span> '<span class="token number">3.1</span>'
services<span class="token operator">:</span>
  nginx<span class="token operator">:</span>
    restart<span class="token operator">:</span> always
    image<span class="token operator">:</span> daocloud.io/library/nginx<span class="token operator">:</span>latest
    container_name<span class="token operator">:</span> nginx
    ports<span class="token operator">:</span>
      - <span class="token number">80</span><span class="token operator">:</span><span class="token number">80</span>
    volumes<span class="token operator">:</span>
      - /opt/docker_nginx/conf.d/<span class="token operator">:</span>/etc/nginx/conf.d
      - /opt/docker_nginx/img<span class="token operator">:</span>/date/img     #新增的映射数据卷
      - /opt/docker_nginx/html<span class="token operator">:</span>/data/html   #新增的映射数据卷</code></pre>
<h3 id="Nginx的集群"><a href="#Nginx的集群" class="headerlink" title="Nginx的集群"></a>Nginx的集群</h3><pre><code>单点故障，避免nginx的宕机，导致整个程序的崩溃

准备多台Nginx

准备keepalived，监听nginx的健康状况

准备haproxt，提供一个虚拟的路径，统一的去接受用户的请求</code></pre>
<p><img src="https://s3.jpg.cm/2020/08/24/uCyV2.png"></p>
<script>
        document.querySelectorAll('.github-emoji')
          .forEach(el => {
            if (!el.dataset.src) { return; }
            const img = document.createElement('img');
            img.style = 'display:none !important;';
            img.src = el.dataset.src;
            img.addEventListener('error', () => {
              img.remove();
              el.style.color = 'inherit';
              el.style.backgroundImage = 'none';
              el.style.background = 'none';
            });
            img.addEventListener('load', () => {
              img.remove();
            });
            document.body.appendChild(img);
          });
      </script>
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://gitee.com/yueyueniao-gif/yueyueniao-gif.git" rel="external nofollow noreferrer">Wang Yue Niao</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://gitee.com/yueyueniao-gif/yueyueniao-gif.git/yueyueniao-gif/2020/08/20/nginx/">https://gitee.com/yueyueniao-gif/yueyueniao-gif.git/yueyueniao-gif/2020/08/20/nginx/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="https://gitee.com/yueyueniao-gif/yueyueniao-gif.git" target="_blank">Wang Yue Niao</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/yueyueniao-gif/tags/Nginx/">
                                    <span class="chip bg-color">Nginx</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/yueyueniao-gif/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/yueyueniao-gif/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/yueyueniao-gif/medias/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/yueyueniao-gif/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/yueyueniao-gif/2020/08/21/docker01/">
                    <div class="card-image">
                        
                        
                        <img src="/yueyueniao-gif/medias/featureimages/1.jpg" class="responsive-img" alt="Docker01">
                        
                        <span class="card-title">Docker01</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            Docker介绍Docker是一个开源的应用容器引擎；是一个轻量级容器技术；
Docker支持将软件编译成一个镜像；然后在镜像中各种软件做好配置，将镜像发布出去，其他使用者可以直接使用这个镜像；
运行中的这个镜像称为容器，容器启动是非常快速
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2020-08-21
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/yueyueniao-gif/categories/Docker/" class="post-category">
                                    Docker
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/yueyueniao-gif/tags/Docker/">
                        <span class="chip bg-color">Docker</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/yueyueniao-gif/2020/08/19/springboot-zheng-he-shiro/">
                    <div class="card-image">
                        
                        
                        <img src="/yueyueniao-gif/medias/featureimages/18.jpg" class="responsive-img" alt="springboot整合Shiro">
                        
                        <span class="card-title">springboot整合Shiro</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            SpringBoot集成Shirops: 发现一篇好博客，学完shiro的单Realm可以去看一下多Realm的多种登录方式传送门
准备工作
搭建一个springboot项目，选中web模块即可

导入maven依赖thymeleaf
&l
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2020-08-19
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/yueyueniao-gif/categories/%E6%9D%83%E9%99%90%E6%8E%A7%E5%88%B6/" class="post-category">
                                    权限控制
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/yueyueniao-gif/tags/Shiro/">
                        <span class="chip bg-color">Shiro</span>
                    </a>
                    
                    <a href="/yueyueniao-gif/tags/springboot/">
                        <span class="chip bg-color">springboot</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/yueyueniao-gif/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/yueyueniao-gif/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/yueyueniao-gif/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/yueyueniao-gif/libs/codeBlock/codeShrink.js"></script>


<!-- 代码块折行 -->

<style type="text/css">
code[class*="language-"], pre[class*="language-"] { white-space: pre !important; }
</style>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/yueyueniao-gif/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>


<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=default"></script>

    <footer class="page-footer bg-color">
    
        <link rel="stylesheet" href="/yueyueniao-gif/libs/aplayer/APlayer.min.css">
<style>
    .aplayer .aplayer-lrc p {
        font-size: 12px;
        font-weight: 700;
        line-height: 16px !important;
    }

    .aplayer .aplayer-lrc p.aplayer-lrc-current {
        font-size: 15px;
        color: #42b983;
    }

    
    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body {
        left: -66px !important;
    }

    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body:hover {
        left: 0px !important;
    }

    
</style>
<div class="">
    
    <div class="row">
        <meting-js class="col l8 offset-l2 m10 offset-m1 s12"
                   server="netease"
                   type="playlist"
                   id="2566555574"
                   fixed='true'
                   autoplay='false'
                   theme='#42b983'
                   loop='all'
                   order='random'
                   preload='auto'
                   volume='0.7'
                   list-folded='true'
        >
        </meting-js>
    </div>
</div>

<script src="/yueyueniao-gif/libs/aplayer/APlayer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script>

    
    <div class="container row center-align" style="margin-bottom: 0px !important;">
       <h2>没有任何动物比蚂蚁更勤奋，然而它却最沉默寡言</h2><br><br>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/yueyueniao-gif/js/search.js"></script>
<script type="text/javascript">
$(function () {
    searchFunc("/yueyueniao-gif/search.xml", 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/yueyueniao-gif/libs/materialize/materialize.min.js"></script>
    <script src="/yueyueniao-gif/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/yueyueniao-gif/libs/aos/aos.js"></script>
    <script src="/yueyueniao-gif/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/yueyueniao-gif/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/yueyueniao-gif/js/matery.js"></script>

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/yueyueniao-gif/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/yueyueniao-gif/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    

    

    

    
    <script src="/yueyueniao-gif/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
